MAKING VARIABLES with VAR - ViSta's Variable-Object Maker


The VAR function creates a XLS+ variable-object. 

Syntax: (var variable &optional form &key (type numeric))

VAR represents the XLS+ variable object by two variables: VARIABLE and $VARIABLE.
 
VARIABLE is an XLS variable whose name is bound to the value of the result of evaluating form. The name of the new XLS variable is added to the $free-vars and $all-vars lists. 

The variable type can be specified as being 'category, 'numeric, 'ordinal, 'freq, or 'label. If not specified, the variable type will be 'numeric when all values in the result of evaluating FORM are numeric, otherwise the type will be 'category. 

If the name VARIABLE involves dashes, an additional XLS variable is created where the dashes are replaced by underscores, facilitating ViVa processing. 

$VARIABLE is an XLS+ variable-object whose name is bound to the variable object. The new XLS+ variable name is not added to any lists, nor is it checked for dashes. You can send the :TYPE :NAME and :VALUE messages to $VARIABLE. 

If either VARIABLE or $VARIABLE is already bound and the global variable *ASK-ON-REDEFINE* is not nil then you are asked if you want to redefine the variable.

The form (VAR VARIABLE) reports the value of VARIABLE, if it exists.

Example: uses VAR VIVA and DATASET together

> (var final-points (* 2 (list 78 45 67 93 89)))
(156 90 134 186 178)
> final-points
(156 90 134 186 178)
> final_points
(156 90 134 186 178)
> $final-points
#<Object: b1ff10, prototype = VAR-PROTO>
> (send $final-points :value)
(156 90 134 186 178)
> (send $final-points :type)
NUMERIC
> (send $final-points :name)
FINAL-POINTS
> [midterm=list(23,10,14,30,28)]
(23 10 14 30 28)
> [total=final-points+midterm]
"; evaluation error: The variable FINAL is unbound."
> [total=final_points+midterm]
(179 100 148 216 206)
> (defun points-to-grade (points)
    (mapcar #'(lambda (score)
             (cond ((< 199 score) "A")
               ((< 174 score 200) "B")
               ((< 149 score 175) "C")
               ((< 124 score 150) "D")
               ((<   0 score 125) "F")))
            points))
POINTS-TO-GRADE
> (var grades (points-to-grade total))
("B" "F" "D" "A" "A")
> grades
("B" "F" "D" "A" "A")
>
> $grades
#<Object: d8da98, prototype = VAR-PROTO>
> (send $grades :type)
CATEGORY
> (dataset overall midterm final-points total grades
           :types (numeric numeric numeric category))
OVERALL
> 
